var con = new Vue({
    el: "#contain",
    data: {
        foods: {}
    },
    mounted: function () {
        this.findFood();
    },
    methods: {
        findFood: function () {
            axios.get("../food/findFood").then(rs => {
                if (rs.status == 200) {
                    if (rs.data.code == 200) {
                        this.foods = rs.data.data;
                    }
                }
            });
        }
    }
});

function reset() {
    $(".hh").val("");
};

function findToLike() {
    var fname = $(".hh").val();
    $.post("../food/findToLike", {"fname": fname}, rs => {
        if (rs.code == 200) {
            con.$data.foods = rs.data;
        }
    });
};
function updateFood(obj){
    $(".tts").css({display: 'block', opacity: '1', zIndex: '6'});
    $(".mask").css({display: 'block'});
    $(".btn2").css({display:'block'})
    $(".btn1").css({display:'none'});
    var fid = $(obj).parent().siblings().eq(0).text();
    var fname = $(obj).parent().siblings().eq(1).text();
    var ftype = $(obj).parent().siblings().eq(2).text();
    var fstatus = $(obj).parent().siblings().eq(3).text();
    var fcount = $(obj).parent().siblings().eq(4).text();
    $(".fid").val(fid);
    $(".fname").val(fname);
    $(".ftype").val(ftype);
    $(".fstatus").val(fstatus);
    $(".fcount").val(fcount);
};
function addFood(){
    $(".tts").css({display: 'block', opacity: '1', zIndex: '6'});
    $(".mask").css({display: 'block'});
    $(".btn1").css({display:'block'})
    $(".btn2").css({display:'none'})
};
function delFood(obj){
    var fid = $(obj).parent().siblings().eq(0).text();
    $.post("../food/delFood",{"fid":fid},rs => {
        if (rs.code == 200){
            alert("删除成功")
            window.location.reload();
        }
    })
};
$(function (){
    $(".btn1").click(function () {
        var fname = $(".fname").val();
        var ftype = $(".ftype").val();
        var fcount = $(".fcount").val();
        var fstatus = $(".fstatus").val();
        $.post("../food/addFood",{"fname":fname,"fstatus":fstatus,"fcount":fcount,"ftype":ftype},function (data){
            if (data.code == 200 && data.data > 0){
                alert("添加成功")
            }
        });
        cancelData();
        window.location.reload();
    });
    $(".btn2").click(function () {
        var fid = $(".fid").val();
        var fname = $(".fname").val();
        var ftype = $(".ftype").val();
        var fstatus = $(".fstatus").val();
        var fcount = $(".fcount").val();
        $.post("../food/updateFood",{"fid":fid,"fname":fname,"ftype":ftype,"fstatus":fstatus,"fcount":fcount},function (data){
            if (data.code == 200 && data.data > 0){
                alert("修改成功")
            }
        });
        cancelData();
        window.location.reload();
    });
});
function cancelData() {
    //更新数据的框关闭
    $(".tts").css({display: 'none'});
    //蒙版消失
    $(".mask").css({display: 'none'});
};